package com.lanou.elh.sysmanage.item_manage;

public class ResultUtil<T> {

    private Result<T> result;

    private ItemResult<T> itemResult;

    public ResultUtil() {
        result = new Result<>();
        result.setSuccess(true);
        result.setMessage("success");
        result.setCode(200);
    }

    public Result<T> setData(T t) {
        this.result.setResult(t);
        this.result.setCode(200);
        return this.result;
    }


    public ItemResult<T> setData(T t, Integer draw, Integer recordsTotal, Integer recordsFiltered) {
        itemResult = new ItemResult<>();
        this.itemResult.setResult(t);
        this.itemResult.setCode(200);
        this.itemResult.setDraw(draw);
        this.itemResult.setRecordsTotal(recordsTotal);
        this.itemResult.setRecordsFiltered(recordsFiltered);
        return this.itemResult;
    }

    public Result<T> setData(T t, String msg) {
        this.result.setResult(t);
        this.result.setCode(200);
        this.result.setMessage(msg);
        return this.result;
    }

    public Result<T> setErrorMsg(String msg) {
        this.result.setSuccess(false);
        this.result.setMessage(msg);
        this.result.setCode(500);
        return this.result;
    }

    public Result<T> setErrorMsg(Integer code, String msg) {
        this.result.setSuccess(false);
        this.result.setMessage(msg);
        this.result.setCode(code);
        return this.result;
    }


}
